package leetcode.code1392;

import leetcode.IDebug;
import leetcode.helper.H;

//超出时间限制
public class Solution2 implements IDebug {

	public String longestPrefix(String s) {
		char[] cs = s.toCharArray();
		String ans = "";
		for (int i = 1; i < cs.length; i++) {
			String str1 = new String(cs, 0, i);
			String str2 = new String(cs, cs.length - i, i);
			if (str1.equals(str2)) {
				ans = str1;
			}
		}
		return ans;
	}

	private long hash2(long hash, int basic, int mod, int add, long mul) {
		return (hash + add * mul) % mod;
	}

//	执行用时：308 ms, 在所有 Java 提交中击败了5.11%的用户
//
//	内存消耗：41.7 MB, 在所有 Java 提交中击败了97.16%的用户
//
//	通过测试用例：76 / 76
//	private long pow(int basic, int n, int mod) {
//		if (n == 0)
//			return 1;
//		long b = pow(basic, n >> 1, mod) % mod;
//		long bb = b * b % mod;
//		return (n & 1) == 0 ? bb : bb * basic % mod;
//	}

	private long hash1(long hash, int basic, int mod, int add) {
		return (hash * basic + add) % mod;
	}

	@Override
	public void debug4() {
		H.compare("abababxx", this.longestPrefix("abababxxabababxx"));
		H.compare("abab", this.longestPrefix("ababab"));
		H.compare("l", this.longestPrefix("level"));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution2 so = new Solution2();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();
		char[] cs = "Hello".toCharArray();
		System.out.println(new String(cs, 0, 0));
	}

}
